const initState = {
    inputvlaue: '',
    nolist: [],
    yeslist: [],
}

export function todoReducer(state = initState, action) {
    console.log(action)
    switch (action.type) {
        case "addTodo":
            var flag = false;
            state.nolist.forEach(ele => {
                if (ele.text === action.text) {
                    window.console.log("不能添加相同的todo");
                    flag = true;
                }
            })

            if (!flag) {
                var todo = {
                    text: action.text,
                    status: "pedding"
                }
            }
            state.nolist.push(todo)
            return {
                nolist: [...state.nolist],
                yeslist: state.yeslist
            };

        case "YesTodo":
            state.nolist.forEach((ele,index) => {
                if (ele.text === action.goYes.text) {
                   state.nolist.splice(index,1);
                }
            })

            // action.todo.status = "finished";
            state.yeslist.push(action.goYes)
            return {
                nolist: [...state.nolist],
                yeslist: [...state.yeslist]
            };
        default:
            return state;
    }
}